package com.xinlianshiye.im.controller;

import com.xinlianshiye.im.bean.App;
import com.xinlianshiye.im.service.AppService;
import com.xinlianshiye.clouds.common.exception.WebMessage;
import com.xinlianshiye.clouds.common.exception.WebMessageBuilder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/im/app")
@Api(tags = "IM应用", description = "IM应用")
public class IMAppController {

    private final AppService appService;
    protected final WebMessageBuilder messageBuilder;

    public IMAppController(AppService appService, WebMessageBuilder messageBuilder) {
        this.appService = appService;
        this.messageBuilder = messageBuilder;
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存", notes = "保存")
    public WebMessage<App> save(@RequestBody App app) {
        return messageBuilder.success(appService.save(app));
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询", notes = "查询")
    public WebMessage<List<App>> list() {
        return messageBuilder.success(appService.list());
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除", notes = "删除（只能删除未使用过的）")
    public WebMessage<?> delete(Integer id) {
        appService.delete(id);
        return messageBuilder.success();
    }
}
